<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>


    <c:if test="${'insert' eq operType}">
        <c:set var="isEditablePage" value="true" scope="request"></c:set>
    </c:if>
    <c:if test="${'edit' eq operType}">
        <c:set var="isEditablePage" value="false" scope="request"></c:set>

        <c:set var="isEditablePage" value="false" scope="request"></c:set>
        <c:if test="${(empty backup.statusCust && empty backup.statusInsp )
                     || ('E1' eq backup.statusCust && 'E1' eq backup.statusInsp)
                     || ('1' eq backup.statusInsp || '4' eq backup.statusInsp || '9' eq backup.statusInsp)}">
            <c:set var="isEditablePage" value="true" scope="request"></c:set>
        </c:if>
    </c:if>
</head>
<body>
<form id="form" >
    <ui:custParamQry></ui:custParamQry>
    <input type="hidden" name="id" value="${backup.id}">
    <div class="content content_frame">
        <h3 class="mainTitle">
            <img src="${basePath}/images/icon2.png"/>申报主体备案
        </h3>
        <br/>
        <table class="table1" style="padding-top: 5px!important;">
            <tr>
                <td width="50%" style="text-align: center">
                    <span style="font-size:16px; color:#418dd9;">关备案状态:</span>
                    ${empty backup.statusCustDisplay ? '暂无' : backup.statusCustDisplay}
                </td>
                <td style="text-align: left">
                    <span style="font-size:16px; color:#418dd9;">检备案状态:</span>
                    ${empty backup.statusInspDisplay ? '暂无' : backup.statusInspDisplay}

                    <c:if test="${not empty backup.backupNoInsp}">
                        <span style="font-size:14px; color:#418dd9;">检备案号:</span>
                        ${backup.backupNoInsp}
                    </c:if>
                </td>
            </tr>
        </table>
        <br>

        <table class="table22">
            <colgroup>
                <col width="18%">
                <col width="30%">
                <col width="15%">
                <col width="35%">
            </colgroup>
            <tr>
                <th colspan="4">企业基本信息</th>
            </tr>
            <tr>
                <td>备案主体</td>
                <td>
                    <label class="radioLabel">
                        <input type="radio" name="backupSubject" value="0"
                        ${'0' eq backup.backupSubject ? 'checked' : ''}> 企业
                    </label>
                    <label class="checkLabel">
                        <input type="radio" name="backupSubject" value="1"
                        ${'1' eq backup.backupSubject ? 'checked' : ''}> 个人
                    </label>
                </td>
                <td colspan="2">
                    <div class="ent_flag">
                        <c:if test="${isEditablePage && 'E2' ne backup.statusCust}">
                        <div style="float: right;"  class="customizeBtn" id="fetchCiqBackupBtn" >
                            <a> <i class='fa fa-download'></i><span style="padding-left:5px;">获取总局备案信息</span></a>
                        </div>
                            <div style="float: right;padding-left:15px;padding-right: 5px">
                                <div style="float: left;"><input type="text" class="input1" placeholder="总局备案号"
                                                                 name="ciqBackupNo"  value="${backup.ciqBackupNo}"></div>
                            </div>
                            <div style=" float: right;" class="customizeBtn" id="readCustCardBtn">
                                <a> <i class='fa fa-download'></i><span style="padding-left:5px;">读海关企业法人卡 </span></a>
                            </div>
                        </c:if>
                    </div>
                </td>
            </tr>
            <tr class="ent_flag">
                <td>申报主体名称</td>
                <td width=""><input type="text" class="input1" readonly="readonly"
                                    name="subjectName" value="${backup.subjectName}">
                </td>

                <td>IC卡号</td>
                <td width="">
                    <input type="text" name="icId" readonly="readonly"
                           value="${backup.icId}">
                </td>
            </tr>
            <tr class="ent_flag">
                <td>组织机构/统一社会信用代码</td>
                <td><input type="text" class="input1" readonly="readonly"
                           name="entOrgCode" value="${backup.entOrgCode}"></td>

                <td>海关10位编码</td>
                <td><input type="text" class="input1 " readonly="readonly"
                           name="customsId" value="${backup.customsId}">
                </td>
            </tr>
            <tr class="ent_flag">

                <td>操作员姓名</td>
                <td>
                    <input type="text" name="operator" readonly="readonly"
                           value="${backup.operator}">
                </td>
                <td>报关员注册编号</td>
                <td width=""><input type="text" class="input1 " readonly="readonly"
                                    name="declaretorId" value="${backup.declaretorId}">
                </td>
            </tr>
            <tr class="ent_flag">
                <td>IC卡证书信息</td>
                <td colspan="3">
                    <input type="text" name="icCaInfo" readonly="readonly"
                           value="${backup.icCaInfo}">
                </td>
            </tr>
            <tr class="person_flag">
                <td>姓名</td>
                <td width=""><input type="text" class="input1"  disabled
                                    name="personName" value="${backup.personName}">
                </td>
                <td>身份证号</td>
                <td><input type="text" class="input1"  disabled
                           name="personCert" value="${backup.personCert}"></td>

            </tr>

            <tr>
                <td>业务类型</td>
                <td>
                    <label class="checkLabel">
                        <input type="checkbox" name="busiType" value="export"
                        ${'1' eq backup.busiTypeExport ? 'checked' : ''}> 出口
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="busiType" value="import"
                        ${'1' eq backup.busiTypeImport ? 'checked' : ''}> 进口
                    </label>
                    <input type="hidden" name="busiType"/>
                </td>

                <td>业务模式</td>
                <td>
                    <label class="checkLabel">
                        <input type="checkbox" name="busiMode" value="normalExport"
                        ${'1' eq backup.busiModeNormalExport ? 'checked' : ''}> 一般出口
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="busiMode" value="taxExport"
                        ${'1' eq backup.busiModeTaxExport ? 'checked' : ''}> 保税出口
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="busiMode" value="normalImport"
                        ${'1' eq backup.busiModeNormalImport ? 'checked' : ''}> 一般进口
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="busiMode" value="taxImport"
                        ${'1' eq backup.busiModeTaxImport ? 'checked' : ''}> 保税进口
                    </label>
                    <input type="hidden" name="busiMode">
                </td>
            </tr>
            <tr>

            </tr>
            <tr>
                <td>申报主体类型</td>
                <td colspan="3">
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="pl"
                        ${'1' eq backup.declTypePl ? 'checked' : ''}> 电商平台
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="cbe"
                        ${'1' eq backup.declTypeCbe ? 'checked' : ''}> 电商企业
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="lst"
                        ${'1' eq backup.busiModeTaxImport ? 'checked' : ''}> 国内物流
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="foreignLst"
                        ${'1' eq backup.declTypeForeignLst ? 'checked' : ''}> 国际物流
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="pay"
                        ${'1' eq backup.declTypePay ? 'checked' : ''}> 支付企业
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="store"
                        ${'1' eq backup.declTypeStore ? 'checked' : ''}> 仓储企业
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="agent"
                        ${'1' eq backup.busiModeTaxImport ? 'checked' : ''}> 外贸代理企业
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="insp"
                        ${'1' eq backup.declTypeInsp ? 'checked' : ''}> 报检企业
                    </label>
                    <label class="checkLabel">
                        <input type="checkbox" name="declType" value="cust"
                        ${'1' eq backup.declTypeCust ? 'checked' : ''}> 报关企业
                    </label>
                    (出口清单或进口个人物品申报单的申报主体请勾选此身份)
                    <input type="hidden" name="declType">
                </td>
            </tr>
            <tr>
                <td>进出口现场</td>
                <td>
                    <ui:tsingletableautocomplete
                            keyFieldName="ieArea"
                            valueFieldName="ieAreaXXX"
                            tableName="S_CUSTOMS_EPORT"
                            key="CUSTOMS_CODE"
                            value="CUSTOMS_NAME"
                            defaultKey="${backup.ieArea}"
                            defaultValue=""
                            whereConditon=" AND CUSTOMS_CODE LIKE '42%' "
                            css="input1"
                            />
                </td>

                <td>属地检机构代码</td>
                <td>
                    <ui:tsingletableautocomplete
                            keyFieldName="ciqorgtypecode"
                            valueFieldName="ciqorgtypecodexxxx"
                            tableName="S_BBD_ORGANIZE"
                            key="ORG_CODE"
                            value="ORG_CNAME"
                            defaultKey="${backup.ciqorgtypecode}"
                            defaultValue=""
                            whereConditon=" AND ORG_CODE LIKE '37%'"/>
                </td>
            </tr>
            <tr>
                <td>申报主体注册地</td>
                <td>
                    <label class="radioLabel">
                        <input type="radio" name="declSubjectRegArea" value="0"
                                ${'0' eq backup.declSubjectRegArea ? 'checked' : ''}> 境内
                    </label>
                    <label class="checkLabel">
                        <input type="radio" name="declSubjectRegArea" value="1"
                        ${'1' eq backup.declSubjectRegArea ? 'checked' : ''}> 境外
                    </label>
                </td>
                <td>国家地区</td>
                <td>
                    <ui:tsingletableautocomplete
                            keyFieldName="country"
                            valueFieldName="countryXXXX"
                            tableName="S_TRADE_COUNTRY_E"
                            key="CODE_C"
                            value="NAME_C"
                            defaultKey="${backup.country}"
                            />
                </td>

            </tr>
            <tr>
                <td>纳税人性质</td>
                <td>
                    <ui:tsingletableautocomplete
                            keyFieldName="taxPayerNature"
                            valueFieldName="taxPayerNaturexxxx"
                            tableName="DICT_ITEM"
                            key="ITEM_KEY"
                            value="ITEM_VALUE"
                            groupId="taxPayerNature"
                            defaultKey="${backup.taxPayerNature}"
                            defaultValue=""
                            css=""/>

                <td>纳税人识别号</td>
                <td><input type="text" class="input1 " placeholder="纳税人识别号"
                               name="taxPayerNo" value="">
                </td>
            </tr>
            <tr>
                <td>注册资本</td>
                <td>
                    <div style="float:left;width:100%">
                        <div style="float:left;width:60%">
                            <input type="text" class="input1 " placeholder="注册资本"
                                   name="registeredCapital" value="${backup.registeredCapital}">
                        </div>
                        <div style="float:left;width:40%">
                            <ui:tsingletableautocomplete
                                    keyFieldName="registeredCapitalCurrency"
                                    valueFieldName="registeredCapitalCurrencyXXXX"
                                    tableName="S_CURRENCY_E"
                                    key="CODE_C"
                                    value="NAME_C"
                                    defaultKey="${backup.registeredCapitalCurrency}"
                                    defaultValue=""
                                    css="appendAutocomplete"/>
                        </div>
                    </div>

                </td>
                <td>投资总额</td>
                <td>
                    <div style="float:left;width:100%">
                        <div style="float:left;width:60%">
                            <input type="text" class="input1 " placeholder="投资总额"
                                   name="totalInvestment" value="${backup.totalInvestment}">
                        </div>
                        <div style="float:left;width:40%">
                            <ui:tsingletableautocomplete
                                    keyFieldName="totalInvestmentCurrency"
                                    valueFieldName="totalInvestmentCurrencyXXXX"
                                    tableName="S_CURRENCY_E"
                                    key="CODE_C"
                                    value="NAME_C"
                                    defaultKey="${backup.totalInvestmentCurrency}"
                                    defaultValue=""
                                    css="appendAutocomplete"/>
                        </div>
                    </div>
                </td>
            </tr>
            <tr>

                <td>法人</td>
                <td><input type="text" class="input1 " placeholder="法人"
                           name="lawMan" value="${backup.lawMan}">
                </td>

                <td>联系人</td>
                <td><input type="text" class="input1 " placeholder="联系人"
                           name="contactMan" value="${backup.contactMan}"></td>
            </tr>
            <tr>
                <td>联系电话</td>
                <td><input type="text" class="input1 " placeholder="联系电话"
                           name="contactManMobile" value="${backup.contactManMobile}">
                </td>

                <td>Email</td>
                <td><input type="text" class="input1 " placeholder="Email"
                           name="email" value="${backup.email}">
                </td>

            </tr>
            <tr>
                <td>传真号码</td>
                <td><input type="text" class="input1 " placeholder="传真号码"
                           name="faxNo" value="${backup.faxNo}"></td>

                <td>邮政编码</td>
                <td><input type="text" class="input1 " placeholder="邮政编码"
                           name="zipCode" value="${backup.zipCode}"></td>

            </tr>

            <tr>
                <td>平台名称</td>
                <td><input type="text" class="input1 "
                           placeholder="平台名称"
                           name="platform" value="${backup.platform}"></td>
                <td>平台网址</td>
                <td><input type="text" class="input1 " placeholder="平台网址"
                           name="websiteUrl" value="${backup.websiteUrl}"></td>
            </tr>
            <tr>
                <td>所属平台</td>
                <td>
                    <input type="text" class="input1 " placeholder="所属平台"
                           name="ownerPlatform" value="${backup.ownerPlatform}">
                    <%--<ui:tsingletableautocomplete--%>
                            <%--keyFieldName="ownerPlatform"--%>
                            <%--valueFieldName="ownerPlatformXXXX"--%>
                            <%--tableName="ECOMMERCE.T_ENTBACKUP_WEBSITE_INSP"--%>
                            <%--key="URL"--%>
                            <%--value="SITENAME"--%>
                            <%--defaultKey="${backup.ownerPlatform}"--%>
                            <%--defaultValue=""--%>
                            <%--whereConditon=" AND URL IS NOT NULL AND SITENAME IS NOT NULL "--%>
                            <%--isCache="false"/>--%>
                </td>
            </tr>
            <tr>
                <td>经营范围</td>
                <td colspan="3">
                    <textarea class="input1 " rows="3" style="width: 100%!important;"
                              placeholder="经营范围" name="busiScope">${backup.busiScope}</textarea>
                </td>

            </tr>
            <tr>
                <td>申报主体地址</td>
                <td colspan="3" id="declSubjectAddrDiv">
                    <div style="float:left;width:100%">
                        <div style="float:left;width:20%">
                            <ui:tsingletableautocomplete
                                    keyFieldName="provinceCode"
                                    valueFieldName="provinceName"
                                    tableName="T_PROVINCE"
                                    key="ID"
                                    value="PROVINCE_NAME"
                                    defaultKey="${backup.provinceCode}"
                                    defaultValue=""
                                    maxRows="100"
                                    placeholder="省份"
                                    onchange="clearCity"/>
                        </div>
                        <div style="float:left;width:20%" id="cityDiv">
                            <ui:tsingletableautocomplete
                                    keyFieldName="cityCode"
                                    valueFieldName="cityName"
                                    tableName="T_CITY"
                                    key="ID"
                                    value="CITY_NAME"
                                    defaultKey="${backup.cityCode}"
                                    defaultValue=""
                                    relateCondition="relateProvince"
                                    maxRows="100"
                                    placeholder="地市"
                                    onchange="clearDistrict"/>
                        </div>
                        <div style="float:left;width:20%" id="districtDiv">
                            <ui:tsingletableautocomplete
                                    keyFieldName="districtCode"
                                    valueFieldName="districtName"
                                    tableName="T_DISTRICT"
                                    key="ID"
                                    value="DISTRICT_NAME"
                                    defaultKey="${backup.districtCode}"
                                    defaultValue=""
                                    relateCondition="relateCity"
                                    maxRows="100"
                                    placeholder="区县"/>
                        </div>
                        <div style="float:left;width:40%">
                            <input type="text" class="input1  " placeholder="地址"
                                   name="address" value="${backup.address}">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>申报主体介绍</td>
                <td colspan="3">
                    <textarea class="input1" rows="3" style="width: 100%"
                           placeholder="申报主体介绍" name="subjectInfo">${backup.subjectInfo}</textarea>
                </td>
            </tr>

            <tr>
                <td>委托声明</td>
                <td colspan="3">

                    <label class="checkLabel">
                        <input type="checkbox" name="agreeItem" value="1" checked>
                        我已阅读并同意
                    </label>
                    <a class='btn-link' onclick="showDeclaration()"><span style='color:#00acec;cursor: pointer;'>本平台服务条款</span></a>
                </td>
            </tr>
        </table>
        <div class="cl"></div>
        <br/>


        <div class="cl"></div>
        <br/>
        <div>
            <jsp:include page="file_upload.jsp" flush="true"></jsp:include>
        </div>
        <input type="hidden" name="indx"/>
        <input type="hidden" id="bizType" value="3"/>
        <br/>


        <table class="" width="100%">
            <tr>
                <td width="33%"></td>
                <td width="33%" align="center" style="text-align: center!important;">
                    <div>
                        <c:if test="${isEditablePage}">
                        <div style=" float: left;width:70px!important;" class="customizeBtn" id="declareBackupBtn" >
                            <a> <i class='fa fa-book'></i><span style="padding-left:5px;">申&nbsp;报  </span></a>
                        </div>
                        <div style=" float: left;width:10px!important;">&nbsp;</div>
                        <div style="float: left;width:70px!important;"  class="customizeBtn"  id="saveBackupBtn" >
                            <a> <i class='fa fa-save'></i><span style="padding-left:5px;">保&nbsp;存</span></a>
                        </div>
                        </c:if>
                        <div style=" float: left;width:10px!important;">&nbsp;</div>
                        <div style="float: left;width:70px!important;"  class="customizeBtn" onclick="toInit()">
                            <a id="replayBtn" > <i class='fa fa-reply'></i><span style="padding-left:5px;">返&nbsp;回</span></a>
                        </div>
                    </div>
                </td>
                <td width="33%"></td>
            </tr>
        </table>

        <br/>
    </div>

</form>
<script>
    function toInit()
    {
        location.href = "${basePath}/entBackup/init";
    }
    function clearCity() {
        $("#cityDiv input").val('');
        $("#districtDiv input").val('');

    }
    function clearDistrict() {
        $("#districtDiv input").val('');
    }
    function relateProvince() {
        if ($("#provinceCode").val() != "") {
            return " AND PROVINCE_ID ='" + $("#provinceCode").val() + "'";
        }

        return "";
    }

    function relateCity() {
        if ($("#cityCode").val() != "") {
            return " AND CITY_ID ='" + $("#cityCode").val() + "'";
        }

        return "";
    }
    function showDeclaration()
    {
        layerAlertOk("本平台消费者承诺:<br>" +
                "本人所购商品系个人自用，现委托网站运营商指定专业报关企业代为办理如下事项：<br>" +
                "（1）代理本人向海关申报；<br>" +
                "（2）代理本人配合海关进行货品查验；<br>" +
                "（3）代理本人向海关缴纳所需税款。<br>" +
                "本人保证遵守《海关法》和国家相关法律法规，保证所提供的身份信息和收货信息真实完整，愿意接受海关、检验检疫机构及其他监管部门的监管。对被委托人在办理上述事项过程中所申报的有关数据，本人均予以认可，并承担相应的法律责任。");
    }


    function save() {
        if ($("#form").formValidateEmpty()) {
            if (($("#entTypeId input[type='checkbox']:checked").length) < 1) {
                showWarningMsg("企业类型不能为空！")
            } else {
                $.ajax({
                    type: "post",
                    async: false,
                    dataType: "json",
                    url: "${basePath}/ent/dist/insertTEntRegDist",
                    data: $('#form').serialize(),
                    success: function () {
                        showOKMessage("保存成功！")
                    },
                    error: function () {
                        showWarningMsg("保存失败！")
                    }
                });
            }
        }
    }

    function removeRule(name)
    {
        var _obj = $("input[name='"+ name +"']");
        _obj.rules("remove", 'required');

         _obj.closest("TD").prev().find('span').remove();
    }
    function addRule(name)
    {
        removeRule(name);

        var _obj = $("input[name='"+ name +"']");
        _obj.rules("add", { required: true });

        var titleTD = _obj.closest("TD").prev();
        titleTD.html("<span style='color:red!important'>*</span>" + titleTD.html());
    }

    function changeEntRules()
    {
        var _pl = $("input[name='declType'][value='pl']").is(":checked");
        if(_pl)
        {
            addRule('platform');
            addRule('websiteUrl');
            addRule('attachInspList[3].annexname');
        }
        else
        {
            removeRule('platform');
            removeRule('websiteUrl');
            removeRule('attachInspList[3].annexname');
        }

        var _import = $("input[name='busiType'][value='import']").is(":checked");
        var _cbe = $("input[name='declType'][value='cbe']").is(":checked");
        if(_import && _cbe)
        {
            addRule('ownerPlatform');
        }
        else
        {
            removeRule('ownerPlatform');
        }

        var _export = $("input[name='busiType'][value='export']").is(":checked");
        if(_export)
        {
            addRule('taxPayerNature');
            addRule('taxPayerNo');
        }
        else
        {
            removeRule('taxPayerNature');
            removeRule('taxPayerNo');
        }

        var _innerArea = $("input[name='declSubjectRegArea'][value='0']").is(":checked");
        if(_innerArea)
        {
            $("#declSubjectAddrDiv input").attr("readonly", false);
            addRule('provinceCode');
            addRule('cityCode');
            addRule('districtCode');
            addRule('address');
        }
        else{
            $("#declSubjectAddrDiv input").val('');
            $("#declSubjectAddrDiv input").attr("readonly", true);
            removeRule('provinceCode');
            removeRule('cityCode');
            removeRule('districtCode');
            removeRule('address');
        }

    }

    function changePersonRules()
    {
        var _pl = $("input[name='declType'][value='pl']").is(":checked");
        if(_pl)
        {
            addRule('platform');
            addRule('websiteUrl');
            addRule('attachInspList[3].annexname');
        }
        else
        {
            removeRule('platform');
            removeRule('websiteUrl');
            removeRule('attachInspList[3].annexname');
        }

        var _import = $("input[name='busiType'][value='import']").is(":checked");
        var _cbe = $("input[name='declType'][value='cbe']").is(":checked");
        if(_import && _cbe)
        {
            addRule('ownerPlatform');
        }
        else
        {
            removeRule('ownerPlatform');
        }


        removeRule('taxPayerNature');
        removeRule('taxPayerNo');

        var _innerArea = $("input[name='declSubjectRegArea'][value='0']").is(":checked");
        if(_innerArea)
        {
            $("#declSubjectAddrDiv input").attr("readonly", false);
            addRule('provinceCode');
            addRule('cityCode');
            addRule('districtCode');
            addRule('address');
        }
        else{
            $("#declSubjectAddrDiv input").val('');
            $("#declSubjectAddrDiv input").attr("readonly", true);
            removeRule('provinceCode');
            removeRule('cityCode');
            removeRule('districtCode');
            removeRule('address');
        }

        removeRule("registeredCapital");
        removeRule("registeredCapitalCurrency");
    }
    function changeRules()
    {
        var _isEnt = $("input[name='backupSubject'][value='0']").is(":checked");
        if(_isEnt)
        {
            changeEntRules();
            return;
        }

        changePersonRules();
    }

    function changeSubject()
    {
        var _personChecked = $("input[name='backupSubject']:eq(1)").is(":checked");
        if(_personChecked)
        {
            $(".person_flag").show();
            $(".person_flag input").attr('disabled', false);

            $(".ent_flag").hide();
            $(".ent_flag input").attr('disabled', true);
        }
        else
        {
            $(".ent_flag").show();
            $(".ent_flag input").attr('disabled', false);

            $(".person_flag").hide();
            $(".person_flag input").attr('disabled', true);
        }
    }
    var isReadCard = false;
    function initBindBtnEvent() {
        var isView = ${'view' eq operType};
        if (isView) {
            return;
        }

        $("input[name='backupSubject']").bind("change", function(){
            try
            {

                var _isEdit = ${'edit' eq operType ? true : false};
                if(_isEdit)
                {
                    $("input[name='backupSubject'][value='${backup.backupSubject}']").attr('checked', true);
                    return;
                }

                changeSubject();
                var _personChecked = $("input[name='backupSubject']:eq(1)").is(":checked");
                var _importCheced = $("input[name='busiMode'][value='normalImport'],input[name='busiMode'][value='taxImport'],input[name='busiType'][value='import']").is(":checked");
                if(_personChecked && _importCheced )
                {
                    $("input[name='busiMode'][value='normalImport'],input[name='busiMode'][value='taxImport'],input[name='busiType'][value='import']").attr("checked",false);
                    layerAlert("备案主体为个人时只能选择出口业务。");

                    return;
                }
            }
            finally{
                changeRules();
            }

        });

        $("input[name='busiType'],input[name='busiMode']").bind("change", function(){

            try{
                if(!this.checked)
                {
                    return;
                }
                var backupSubjectPersonCheced = $("input[name='backupSubject']:eq(1)").is(":checked");
                var _import = $("input[name='busiMode'][value='normalImport'],input[name='busiMode'][value='taxImport'],input[name='busiType'][value='import']");
                if(backupSubjectPersonCheced && _import.is(":checked"))
                {
                    _import.attr("checked", false);
                    layerAlert("备案主体为个人时只能选择出口业务。");

                    return;
                }
            }
            finally
            {
                changeRules();
            }

        });

        $("input[name='declType']").bind("change", function(){

            try{
                if(!this.checked)
                {
                    return;
                }

                var _isExsit = ${empty isExsit ? false : isExsit};
                if( _isExsit && this.value != 'cbe' )
                {
                    this.checked = false;
                    layerAlert("同一个账号已备案再新增备案记录时，只能勾选电商企业身份。");

                    return;
                }

                var declTypePayChecked = $("input[name='declType'][value='pay']").is(":checked");
                var declTypeLstChecked = $("input[name='declType'][value='lst']").is(":checked");
                var declTypeForeignLstChecked = $("input[name='declType'][value='foreignLst']").is(":checked");

                $("input[name='declType']").each(function(){
                    if(!this.checked)
                    {
                        return true;
                    }

                    if((declTypeLstChecked || declTypeForeignLstChecked)
                            && (this.value == "cbe" || this.value == "pl" || this.value == "pay"))
                    {
                        $("input[name='declType'][value='cbe']").attr("checked", false);
                        $("input[name='declType'][value='pl']").attr("checked", false);
                        $("input[name='declType'][value='pay']").attr("checked", false);
                        layerAlert("申报主体类型选择国际物流、国内物流时不能选择电商企业、电商平台、支付企业。");

                        return false;
                    }

                    if(declTypePayChecked && this.value != 'pay')
                    {
                        $("input[name='declType'][value!='pay']").attr("checked", false);
                        layerAlert("申报主体类型选择支付企业时不能选择其他身份。");

                        return false;
                    }

                });
            }
            finally
            {
                changeRules();
            }
        });

        $("input[name='declSubjectRegArea']").bind('change', function(){
            changeRules();
        });

        $("#readCustCardBtn").bind("click", function () {
            isReadCard = false;
            $("#form input[name='icId']").val('');
            $("#form input[name='subjectName']").val('');
            $("#form input[name='entOrgCode']").val('');
            $("#form input[name='customsId']").val('');
            $("#form input[name='operator']").val('');
            $("#form input[name='declaretorId']").val('');
            $("#form input[name='icCaInfo']").val('');

            var custCardInfo = getIcUserInfo();
//            {'icId':'icId', 'entNameCn':'entNameCn','entOrgCode':'entOrgCode21',
//                    'customsId':'customsId','operator':'operator','declaretorId':'declaretorId','icCaInfo':'icCaInfo'
//            };
            if (custCardInfo) {
                $("#form input[name='icId']").val(custCardInfo['icId']);
                $("#form input[name='subjectName']").val(custCardInfo['entNameCn']);
                $("#form input[name='entOrgCode']").val(custCardInfo['entOrgCode']);
                $("#form input[name='customsId']").val(custCardInfo['customsId']);
                $("#form input[name='operator']").val(custCardInfo['operator']);
                $("#form input[name='declaretorId']").val(custCardInfo['declaretorId']);
                $("#form input[name='icCaInfo']").val(custCardInfo['icCaInfo']);
                isReadCard = true;
            }
        });

        $("#fetchCiqBackupBtn").bind("click", function () {

            var _ciqBackupNo = $("#form input[name='ciqBackupNo']");
            if (_ciqBackupNo.val() == '') {
                layerAlert("请输入总局备案号！", function(){
                    _ciqBackupNo.focus().select();
                });
                return;
            }

            layerAlert("总局备案号:" + _ciqBackupNo.val() + "获取不到总局已备案信息");
        });

        $("#saveBackupBtn").bind("click", function () {

            var entSubject = $("input[name='backupSubject']:eq(0)").is(":checked");
            if(entSubject && ${'insert' eq operType ? true : false} && !isReadCard)
            {
                layerAlert("请先读取海关企业法人卡");
                return;
            }

            if (entSubject && $("#form input[name='customsId']").val() == '') {
                layerAlert("获取不到海关十位编码！");
                return;
            }

            if(!isFormatValid("form"))
            {
                return;
            }

            $.post("${basePath}/entBackup/saveBackup",
                    $("#form input,textarea").serialize(),
                    function (result) {
                        if (result['code'] + '' == '1') {
                            layerAlertOk("保存成功！", function(){
                                location.href = "${basePath}/entBackup/edit?id="+result['msg']+"&r=" + Math.random();
                            });
                            return;
                        }

                        layerAlert("保存失败," + result['msg']);
                    },
                    'JSON').error(function (xmlHttpRequest, status, msg) {
                        layerAlert("系统繁忙,保存失败");
                    }
            );
        });

        $("#declareBackupBtn").bind("click", function () {

            var entSubject = $("input[name='backupSubject']:eq(0)").is(":checked");
            if(entSubject && ${'insert' eq operType ? true : false} && !isReadCard)
            {
                layerAlert("请先读取海关企业法人卡");
                return;
            }

            if (entSubject && $("#form input[name='customsId']").val() == '') {
                layerAlert("获取不到海关十位编码！");
                return;
            }

            if(!isValid("form"))
            {
                return;
            }

            $.post("${basePath}/entBackup/saveBackup",
                    $("#form input,textarea").serialize(),
                    function (result) {
                        if (result['code'] + '' == '1') {
                            var _id = result['msg'];
                            $.post("${basePath}/entBackup/declare",
                                    $("#form input,textarea").serialize(),
                                    function (result) {
                                        if (result['code'] + '' == '1') {
                                            layerAlertOk("备案数据提交申请成功！", function(){
                                                location.href = "${basePath}/entBackup/edit?id="+_id+"&r=" + Math.random();
                                            });
                                            return;
                                        }

                                        layerAlert("备案数据提交申请失败," + result['msg']);
                                    },
                                    'JSON').error(function (xmlHttpRequest, status, msg) {
                                        layerAlert("系统繁忙,保存失败");
                                    }
                            );
                            return;
                        }

                        layerAlert("保存失败," + result['msg']);
                    },
                    'JSON').error(function (xmlHttpRequest, status, msg) {
                        layerAlert("系统繁忙,保存失败");
                    }
            );

        });


        $("#attach_delete_btn").bind("click", function () {
            var selectIDs = getSelectIDs('attachList');
            if (selectIDs.length < 1) {
                layerAlert("对不起,您没有选中任何记录");
                return;
            }

            var _data = "id=" + selectIDs.join("&id=").toString();
            showConfirm("确定要删除选中的记录吗?", "系统提示", function () {

                $.ajax({
                    type: "post",
                    url: '${basePath}/entBackup/deleteAttach',
                    data: _data,
                    success: function () {
                        layerAlertOk('删除成功!', function () {
                            $("#attachList").jqGrid('setGridParam', {url: $basePath + "/entBackup/pageAttach"})
                                    .trigger("reloadGrid");
                        });
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layerAlert("系统繁忙,保存失败");
                    }
                });
            });
        });
    }

    function initValid()
    {
        var rules = {
            backupSubject: {minlength:1},
            icId : {minlength:1},
            subjectName : {minlength:1},
            entOrgCode : {minlength:1},
            customsId : {minlength:1},
            operator : {minlength:1},
            busiType:{minlength:1},
            busiMode:{minlength:1},
            declType:{minlength:1},
            ieArea:{minlength:1},
            ciqorgtypecode : {minlength:1},
            declSubjectRegArea: {minlength:1},
            country: {minlength:1},
            registeredCapital:{minlength:1,maxNum:[18,4]},
            registeredCapitalCurrency: {relate:{name:'registeredCapital'}},
            totalInvestment:{maxNum:[18,4]},
            totalInvestmentCurrency: {relate:{name:'totalInvestment'}},
            provinceCode: {minlength:1},
            cityCode: {minlength:1},
            districtCode: {minlength:1},
            address : {minlength:1, maxlength:100},
            lawMan : {minlength:1, maxlength:500},
            contactMan: {minlength:1, maxlength:50},
            contactManMobile:{minlength:1, maxlength:50, phone:true},
            websiteUrl:{url:true},
            email:{email:true},
            faxNo:{maxlength:40},
            taxPayerNo:{maxlength:25},
            zipCode:{maxlength:25},
            busiScope:{minlength:1, maxlength:500},
            ownerPlatform:{maxlength:100},
            subjectInfo:{minlength:1, maxlength:500},
            agreeItem:{minlength:1},
            personName:{minlength:1, maxlength:50},
            personCert:{minlength:1, maxlength:18},
            'attachInspList[0].annexname':{minlength:1},
            'attachInspList[1].annexname':{minlength:1},
            'attachInspList[2].annexname':{minlength:1}
        };
        formValidate("form", rules, true);
    }

    function disabledPage() {

        if (!${isEditablePage}) {
            $("#form input,textarea").attr("disabled", true);
            $("#form a").not('#replayBtn').attr("disabled", "disabled").attr("href", 'javascript:void(0)').unbind('click').attr("onclick", function () {
            });
        }
    }

    $(function () {

        disabledPage();
        initBindBtnEvent();
        initValid();
        changeSubject();
        changeRules();

    });
</script>
</body>
</html>
